import numpy as np
np.set_printoptions(suppress=True)
infilepath=r"seed_profile.txt"
with open(infilepath, "r", encoding='utf-8') as f:
    count=0
    part=0
    group=0
    maxsize=4000
    blocksize=500
    
    for data in f.readlines():
        
        if count>maxsize:
            break   

        if count%blocksize==0 and group==0:
            if count!=0 and len(sm)==blocksize:
                print(count)
                savepath=r"Test_Metadata\metadata_part{}".format(part)
                pk_str=np.array(pk,dtype=object)
                sk_str=np.array(sk,dtype=object)
                msg_array=np.array(msg,dtype=object)
                sm_array=np.array(sm,dtype=object)
                np.savez_compressed(savepath,pk=pk_str,sk=sk_str,counter=counter,msg=msg_array,mlen=mlen,sm=sm_array,smlen=smlen,seed=seed,rejection=nonce,index=index,allbytes=allbytes)
                part+=1
                
            
            counter=np.zeros([blocksize,],dtype=int)
            mlen=np.zeros([blocksize,],dtype=int)
            sm=[]
            msg=[]
            seed=[]
            pk=[]
            sk=[]
            allbytes=[]
            smlen=np.zeros([blocksize,],dtype=int)
            nonce=np.zeros([blocksize,],dtype=int)
            index=np.zeros([blocksize,],dtype=int)
        


        if data.find("counter=")!=-1:
            counter[count%blocksize]=(int(data[8:]))
            group+=1
        
        if data.find("msg=")!=-1:
            msg.append(data[4:].strip())
            group+=1

        if data.find("mlen=")==0:
            mlen[count%blocksize]=(int(data[5:]))
            group+=1

        if data.find("r_allbytes")!=-1:
            allbytes.append(data[14:].strip())
            group+=1
        
        if data.find("sm=")==0 and data.find("smlen=")==-1:
            sm.append(data[3:].strip())
            group+=1

        if data.find("pk=")!=-1:
            pk.append(data[3:].strip())
            group+=1
        
        if data.find("sk=")!=-1:
            sk.append(data[3:].strip())
            group+=1

        if data.find("smlen=")!=-1:
            smlen[count%blocksize]=int(data[6:])
            group+=1
        
        if data.find("nonce=")==0:
            nonce[count%blocksize]=int(data[6:],16)-1
            group+=1

        if data.find("mark_index=")==0:
            index[count%blocksize]=int(data[11:])
            group+=1


        if data.find("seed=")!=-1:
            seed.append(data[5:].strip())
            group+=1

        if group==11:
            group=0
            count+=1





